package com.ruoyi.web.controller.zhuangxiucontroller.orderformController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.zhuangxiumain.orderformMain.WarehouseProduct;
import com.ruoyi.system.service.zhaungxiuservice.shopService.WarehouseProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/store/waproduct")
public class WarehouseProductController extends BaseController {

    @Autowired
    private WarehouseProductService warehouseProductService;

    /**
     * 查询商品库存列表
     */
    @PreAuthorize("@ss.hasPermi('store:product:list')")
    @GetMapping("/list")
    public TableDataInfo list(WarehouseProduct warehouseProduct)
    {
        startPage();
        List<WarehouseProduct> list = warehouseProductService.selectWarehouseProductList(warehouseProduct);
        return getDataTable(list);
    }

    /**
     * 导出商品库存列表
     */
    @PreAuthorize("@ss.hasPermi('store:product:export')")
    @Log(title = "商品库存", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WarehouseProduct warehouseProduct)
    {
        List<WarehouseProduct> list = warehouseProductService.selectWarehouseProductList(warehouseProduct);
        ExcelUtil<WarehouseProduct> util = new ExcelUtil<WarehouseProduct>(WarehouseProduct.class);
        return util.exportExcel(list, "product");
    }

    /**
     * 获取商品库存详细信息
     */
    @PreAuthorize("@ss.hasPermi('store:product:query')")
    @GetMapping(value = "/{wpId}")
    public AjaxResult getInfo(@PathVariable("wpId") Integer wpId)
    {
        return AjaxResult.success(warehouseProductService.selectWarehouseProductById(wpId));
    }

    /**
     * 新增商品库存
     */
    @PreAuthorize("@ss.hasPermi('store:product:add')")
    @Log(title = "商品库存", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WarehouseProduct warehouseProduct)
    {
        return toAjax(warehouseProductService.insertWarehouseProduct(warehouseProduct));
    }

    /**
     * 修改商品库存
     */
    @PreAuthorize("@ss.hasPermi('store:product:edit')")
    @Log(title = "商品库存", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WarehouseProduct warehouseProduct)
    {
        return toAjax(warehouseProductService.updateWarehouseProduct(warehouseProduct));
    }

    /**
     * 删除商品库存
     */
    @PreAuthorize("@ss.hasPermi('store:product:remove')")
    @Log(title = "商品库存", businessType = BusinessType.DELETE)
    @DeleteMapping("/{wpIds}")
    public AjaxResult remove(@PathVariable Integer[] wpIds)
    {
        return toAjax(warehouseProductService.deleteWarehouseProductByIds(wpIds));
    }



}
